Topic 1 Question #3
A Linux systems administrator needs to extract the contents of a file named /home/dev/web.bkp to the /var/www/html/ directory. Which of the following commands should the administrator use?
- A.
cd /var/www/html/ && gzip -c /home/dev/web.bkp | tar xf -
- B.
pushd /var/www/html/ $$ cpio -idv < /home/dev/web.bkp && popd
- C.
tar -c -f /home/dev/web.bkp /var/www/html/
- D.
unzip -c /home/dev/web.bkp /var/www/html/
Answer: B
The scenario requires extracting the contents of the /home/dev/web.bkp backup file to the /var/www/html/ target directory. The suggested answer B correctly implements this workflow using standard Linux administration utilities aligned with XK0-006 CompTIA Linux+ objectives. The command first uses pushd to switch the active working directory to the target /var/www/html/ location, ensuring all extracted content is written to the correct path. It then runs cpio in extract mode with appropriate flags to read the backup file from redirected standard input, extract all contents, create missing parent directories as needed, and log activity for verification. Finally, popd returns the administrator to their original working directory to avoid disrupting subsequent operations. This command is flexible enough to handle common cpio-formatted backup files, a widely used archive format for Linux system backups tested on the XK0-006 exam. Option Analysis:
A. Incorrect. This command uses gzip -c without the required -d decompression flag, so it writes the unmodified compressed backup content to standard output instead of decompressing it. Even if the -d flag was included, this command assumes the backup is a gzipped tar archive, which is not confirmed by the generic .bkp file extension, and the syntax fails to reliably extract content to the target directory for all valid backup formats.
B. Correct. This command follows all requirements for the scenario. pushd /var/www/html/ temporarily changes the working directory to the target extraction path. The cpio -idv command uses -i to enable extract mode, -d to automatically create missing parent directories for extracted files, and -v to verbosely list extracted content for audit. The < redirection operator feeds the /home/dev/web.bkp file to cpio's standard input for processing. The final popd command returns the shell to the original working directory, adhering to Linux administration best practices tested in the XK0-006 exam.
C. Incorrect. The tar -c flag enables archive creation mode, not extraction mode. This command would overwrite the existing /home/dev/web.bkp backup file with a new archive containing the contents of /var/www/html/, which is the opposite of the required extraction task.
D. Incorrect. First, unzip only supports zip-formatted archives, which is not confirmed for the generic .bkp backup file. Second, the unzip -c flag writes extracted content to standard output instead of writing files to the filesystem, and the command uses incorrect syntax for specifying a target extraction directory, as unzip requires the -d flag to define a target directory instead of accepting a positional path argument. This command will not write extracted content to /var/www/html/ even if the backup is a valid zip archive. Key Concepts:
1. Linux Archiving Utility Competency: The XK0-006 CompTIA Linux+ exam tests knowledge of common archiving tools including cpio, tar, gzip, and unzip, including correct mode flags for extract vs create operations, input/output handling, and format compatibility, which is directly assessed in this question.
2. Working Directory Management: Competency with pushd and popd to temporarily modify the active working directory for targeted file operations, as well as chained command operators such as && to sequence dependent commands, is a core XK0-006 objective for Linux filesystem administration.
3. Shell Redirection: Understanding of standard input/output redirection operators such as < to pass file content to a command's standard input is a foundational XK0-006 skill required to correctly construct archive extraction and file manipulation commands. References:
CompTIA Linux+ (XK0-006) Exam Objectives, Linux man-pages Project: cpio(1) Manual Page